<!DOCTYPE html>
<#assign secSelect = JspTaglibs["http://www.casic304.cn/secSelect"] />
<html>
<head>
  <meta charset="utf-8">
  <title>飞行试验奖惩管理基本信息</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
  <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
  <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
  <script type="text/javascript">
    var __ctx = "${ctx}";

  </script>
</head>
<body class="listBody">
<div class="qbdms-bodyDiv">
  <div class="layui-table-view-body qbdms-add-view-body">
    <form class="formPreview layui-form" requrl="${ctx}/qbdms/wQbdFlightJc/getListByRefId"
          lay-filter="wQbdFlightJcDataForm" id="wQbdFlightJcDataForm">
      <input type="hidden" name="refid" value="${wQbdFlightJczb.id}">
      <input type="hidden" name="sfjl" value="${isReward}">

      <div class="qbdms-formTitle">
        ${wQbdFlightJc.xhmc}型号${rewardOrPunishmentStr}分配方案，${rewardOrPunishmentStr}金额${amount} 万元 <i
          class="qbdms-returnOn closeWindow">返回</i></div>
      <p class="qbdms-SubTableTitle"><span>${rewardOrPunishmentStr}分配方案</span></p>
      <div class="qbdms-tableDiv">
        <a modetype="2" class="addFormTr1"
           id="add"><i class="layui-icon layui-icon-addition"></i>新增</a>
        <table class="qbdms-temTable wQbdFlightJcjlcfList subFormTable"
               id="wQbdFlightJcjlcfList" style="min-width: 1560px;">
          <tbody>
          <tr class="temSpace qbdms-temTable-thead">
            <td class="temSpace" style="width: 30px;">
              序号
            </td>
            <td class="temSpace subDialogShowState" style="width: 57px">
              部门/单位名称<span style="color: red;">*</span>
            </td>
            <td class="temSpace subDialogShowState" style="width: 150px">
              ${rewardOrPunishmentStr}金额<span style="color: red;">*</span>
            </td>

            <td class="temSpace subDialogShowState" style="width: 160px">
              核算后金额<span style="color: red;">*</span>
            </td>
            <td class="temSpace subDialogShowState" style="width: 160px">
              备注
            </td>
            <td class="temSpace qbdms-subOptState">
              管理
            </td>
          </tr>
          <tr class="temSpace subContTem">
            <td class="temSpace qbdms-temTable-seNumber">
              <div class="temTag">0</div>
            </td>
            <td class="temSpace qbdms-temTable-td">
              <select requiredFlag="required" name="s:swmc" lay-filter="swmc"
                      class="layui-input"
                      lay-reqtext="部门/单位名称是必填项">
              </select>
            </td>

            <td class="temSpace qbdms-temTable-td qbdms-money temSpace_jcje">
              <input type="text" placeholder="请输入${rewardOrPunishmentStr}金额" autocomplete="off"
                     class="layui-input textInput input_jcje"
                     name="s:jcje" maxlength="50"
                     requiredFlag="required"
                     onchange="input_jcje(this,value)" lay-reqtext="${rewardOrPunishmentStr}金额是必填项">
            </td>
            <td class="temSpace qbdms-temTable-td qbdms-money">
              <input type="text" placeholder="请输入" autocomplete="off"
                     class="layui-input textInput input_jcjeAfter"
                     name="s:hshje" maxlength="50" disabled>
            </td>

            <td class="temSpace qbdms-temTable-td qbdms-money">
              <input type="text" placeholder="请输入" autocomplete="off"
                     class="layui-input textInput"
                     name="s:remark" maxlength="50">
            </td>

            <td class="temSpace qbdms-subOptState">
              <a class="subDeleteTrS RightBtn">删除</a>
            </td>
          </tr>
          </tbody>
        </table>
      </div>
      <div class="layui-form-item btnformItem">
        <p>
                    <span id="hideAndShow">
                        <a lay-submit lay-filter="wQbdTecBasicmanage"
                           class="layui-btn btn-n privateSubmit qbdms-oneBtn"
                           requrl="${ctx}/qbdms/wQbdFlightJc/saveJcjlcf">提交</a>
                    </span>
          <button type="reset" id="closeWindow" style="margin-left: 10px;"
                  class="layui-btn layui-btn-sm btn-save qbdms-oneBtnLine">取消
          </button>
        </p>
      </div>
    </form>
  </div>
</div>


<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>

<script>

  layui.config({
    base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'setter', 'layer', 'propsHandle', 'upload', 'common', 'jquery', 'publicMethods',
    'qbdmsForm'], function () {
    // -----常量声明----------
    var $ = layui.jquery;
    var common = layui.common;
    var setter = layui.setter;  // 配置信息
    var layer = layui.layer;
    var propsHandle = layui.propsHandle;
    var form = layui.qbdmsForm;
    var publicMethods=layui.publicMethods;
    var formId = '${formDefId}' || '';
    var defProps = {
      //viewMould: 'form/formDef/view/formDesign/moulds/', // 组件模块 存放文件 *****
      viewMould: 'moulds/', // 组件模块 存放文件 *****
      formAreaInfo: '.formPreview',
      formAreaInfo: 'html',
      temDate: '.temDate',
      uploadFileBtn: '.uploadFileBtn',
      uploadImgBtn: '.uploadImgBtn',
      richTextArea: '.richTextArea',
      selectInput: '.selectInput',
      radioOptionCont: '.radioOptionCont',
      dataLexiTree: '.dataLexiTree',
      selectorBtn: '.selectorBtn'
    };
    var temQuery = new propsHandle();  // 实例化模板功能部分
    var publicMethods = layui.publicMethods;
    // 初始化模板功能
    temQuery.initTem({
      selectorBtn: defProps.selectorBtn,
      selectorTemPath: setter.views + defProps.viewMould
    });
    $(".subContTem").hide()
    // 子表初始化事件
    temQuery.initSubEvent(defProps, serverPath, setter);
    $(document).on('click', '.subDeleteTrS', function () {
      var tab = $(this).parents('.subFormTable')
      var isDel = $(this).parent().parent()[0].children[0].innerText;
      if (isDel == 1 || isDel == 2) {
        layer.msg("当前数据为固定数据，无法删除！", {icon: 2});
        return false;
      }
      $(this).parent().parent().remove();
      tab.find('tr').each(function (i, item) {
        if (i > 0) {
          $(item).find('td').eq(0).find('.temTag').html(i - 1);
        }
        if (i > 1) {
          $(item).find('[type=radio]').each(function (j, itemj) {
            var nameL = tab.find('tr').eq(1).find('[type=radio]').eq(j).attr('name')
            $(itemj).attr('name', nameL + (i > 2 ? ('_' + (i - 1)) : ''))
          })
        }

      })
      publicMethods.bottomFixd()
    });
    var count = 1;
    $(document).on('click', '.addFormTr1', function () {
      count += 1;
      var modetype = $(this).attr('modetype'),
          copyObj = $(this).parent().children('.subFormTable'),
          copyHtm = copyObj.find('tr').eq(1);
      if (modetype === '2') {
        //在这里做一个转换，控制子表隐藏行的必填
        var copyHtmlStr = copyHtm.html();
        copyHtmlStr = copyHtmlStr.replace(/requiredflag/g, "lay-verify");
        // 表格
        copyObj.append('<tr class="temSpace">' + copyHtmlStr + '</tr>');
        var trArr = copyObj.find('tr');
        trArr.eq(trArr.length - 1).find('td').eq(0).find('.temTag').html(trArr.length - 2);
        trArr.eq(trArr.length - 1).find('.fileUpload').attr("id", "fSkillcerfileList" + count);

        trArr.eq(trArr.length - 1).find('[isinit="1"]').each(function (i, item) {
          $(item).attr('isinit', '2');
        });
        if (trArr.length > 3) {
          trArr.eq(trArr.length - 1).find('[type=radio]').each(function (i, item) {
            $(item).attr('name',
                (trArr.eq(1).find('[type=radio]').eq(i).attr('name')) + '_' + (trArr.length - 2))
          });
        }
        temQuery.initTemEvent(defProps, serverPath, setter);
      } else if (modetype === '1') {
      }
      form.render();
      publicMethods.bottomFixd()
    });
    var orgList = eval('${orgList}');
    common.initDicData("s:swmc", orgList);

    common.updateForm({
      name: 'wQbdFlightJcDataForm',
      idValue: "${id},${isReward}",
      primary: "id",
      beforeSubmitFun: function (data) {
        //- 子表数据 开始 ------------------------------------------------------
        var sub = [];
        $('table.subFormTable').each(function () {
          var table = {
            tableName: $(this).attr('class').split(" ")[1],
            fields: []
          };
          $(this).find('tr.temSpace').each(function (i, item) {    /*修复需要提交隐藏的行数据的bug*/
            if (i > 1) {
              var row = {};
              var objRow = $(this);
              $("input:text[name^='s:'],input[type='hidden'][name^='s:'],textarea[name^='s:'],select[name^='s:'],ul[name^='m:']",
                  objRow).each(function () {
                var name = $(this).attr('name').replace(/.*:/, '');
                row[name] = $(this).val();
              });
              row["sort"] = i - 1;
              table.fields.push(row);
            }
          });
          data.field[table.tableName] = table.fields;
        });
      },
      getCallback: function (data) {
        var returnData = data.data;

        //-修改页面 初始化子表 开始 ------------------------------------------


        $('table.subFormTable').each(function () {
          var table = {
            tableName: $(this).attr('class').split(" ")[1],
            fields: []
          };
          table.fields = returnData;
          for (var i = 0, len = table.fields.length; i < len; i++) {
            var dataRow = table.fields[i];
            var temp = $("." + table.tableName).prev().click();
            //这里有子表表头占一行，子表隐藏行占一行，所以取需要赋值的行时，需要temp=i+2
            var domRow = $(this).find("tr.temSpace:eq(" + (i * 1 + 2) + ")");
            $.each(dataRow, function (j, val) {
              var domItem = domRow.find("[name$='" + j + "']");
              if (domItem) {
                domItem.val(val);
              }

            });
            if (i == 0) {
              var optionObj = document.createElement("option");
              optionObj.text = "型号两总";
              optionObj.value = "型号两总";
              document.getElementsByName("s:swmc")[1].appendChild(optionObj);
              domRow.find("select:last").val("型号两总");
              domRow.find("select:last").attr("disabled", "disabled");
            }
            if (i == 1) {
              var optionObj = document.createElement("option");
              optionObj.text = "院本部项目主管部门";
              optionObj.value = "院本部项目主管部门";
              document.getElementsByName("s:swmc")[2].appendChild(optionObj);
              domRow.find("select:last").val("院本部项目主管部门");
              domRow.find("select:last").attr("disabled", "disabled");
            }
            if (i > 1) {
              $.each(dataRow, function (j, val) {
                var domItem = domRow.find("[name$='" + j + "']");
                if (domItem) {
                  domItem.val(val);
                }

              });
            }

          }
        });

      },

      updateCallback: function (data) {
        if (common.filterRecord(data)) {
          if ($(".privateSubmit")) {
            $(".privateSubmit").attr("disabled", false).css("pointer-events", "auto");
          }
          layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'}, function (index) {
            layer.close(index);
            window.location.href = '${ctx}/qbdms/wQbdFlightJc/view/processList';
          });
        } else {
          layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
        }
        return false;
      }
    });

    $("#closeWindow,.closeWindow").click(function () {
      window.location.href = '${ctx}/qbdms/wQbdFlightJc/view/processList';
    });

  });


</script>

<script>


  function input_jcje(self, val) {
    layui.use(['jquery'], function () {
      var $ = layui.jquery;
      var sum = 0;
      var sumafter = 0;
      var resultFour = 0;
      var amount = "${amount}";
      if (val < 0) {
        alert('金额不能为负数')
        return
      }
      var numVal = Number(val).toFixed(2)
      if(numVal=="NaN"){
        numVal=0;
        $(self).val(numVal)
      }
      setval(self, numVal / 4)
      var jcje = document.getElementsByName("s:jcje")
      for (var i = 0; i < jcje.length; i++) {
        sum += Number(jcje[i].value)
        if (i < 3) {
          //前2个不计算4
          setval(jcje[i], '')
        }

      }
      if (sum > amount) {
        var $siblings = $(self).parents(".temSpace_jcje").parent().siblings('.temSpace')
        //排他并去掉第一个匹配项
        for (var i = 1; i < $siblings.length; i++) {
          var sunEle = $($siblings[i]).find('.input_jcje').val()
          sumafter += Number(sunEle)
        }
        var result = Math.abs(amount - sumafter)
        resultFour = result / 4
        $(self).val(result.toFixed(2))
        setval(self, resultFour.toFixed(2))
        for (var i = 0; i < jcje.length; i++) {
          sum += Number(jcje[i].value)
          if (i < 3) {
            //前2个不计算4
            setval(jcje[i], '')
          }

        }
      }
    });

  }

  function setval(ele, value) {
    layui.use(['jquery'], function () {
      var $ = layui.jquery;
      $(ele).parents('.temSpace_jcje').next().find('.input_jcjeAfter').val(Number(value).toFixed(2))
    })
  }

</script>
<style>
  .tableCut {
    padding: 0px !important;
    position: relative;
    width: 100px;
    background: url("${ctx}/formStatic/style/res/cut.png") no-repeat center center !important;
    background-size: 100% 100% !important
  }

  .tableCut > div:nth-child(1) {
    position: absolute;
    top: 5%;
    right: 3px;

  }

  .tableCut > div:nth-child(2) {
    position: absolute;
    top: 38%;
    right: 3px;
  }

  .tableCut > div:nth-child(3) {
    position: absolute;
    bottom: 5%;
    left: 10px;
  }

  .doNotDelThisDiv {
    min-height: 36px;
  }

  .uploadFileList > span {
    display: block;
  }
</style>
</body>
</html>